<template>
  <el-col v-loading="loading.state">
    <el-col>
      <el-table :data="orgData">
        <el-table-column prop="org" label="分配机构" align="center" min-width="120"></el-table-column>
        <el-table-column prop="caseNumber" label="当前持有案件数" align="center" min-width="120"></el-table-column>
        <el-table-column prop="caseNum" label="确认分配案件数" align="center" min-width="120"></el-table-column>
      </el-table>
    </el-col>
    <el-col class="text-center btns">
      <el-button @click="orgPreStep">上一步</el-button>
      <el-button @click="orgConfirm">确认分配</el-button>
      <el-button @click="orgCancel">取消</el-button>
    </el-col>
  </el-col>
</template>
<script>
  import net from '@/util/net'
  import servers from '@/config/servers'

  export default {
    name: 'organization-reallocate',
    data() {
      return {
        loading: {
          state: false
        },
        // 服务接口列表
        server: {
          getCaseNums: servers.CaseManage.get_case_nums, // 获取机构持有案件数
          distributeCeaseInfoAgin: servers.CaseManage.distribute_cease_info_agin // 案件分配确认
        },
        // 机构
        orgData: [],
        multipleSelection: []
      }
    },
    methods: {
      /**
       * 打开刷新
       */
      refresh(multipleSelection) {
        this.multipleSelection = multipleSelection
        this.orgData = []
        let obj = {}
        net.send({
          server: this.server.getCaseNums,
          data: {
            degrId: this.$store.state.caseManage.case_allot_org.deptId
          }
        }).then(data => {
          obj.caseNumber = data
          obj.org = this.$store.state.caseManage.case_allot_org.name
          obj.caseNum = this.multipleSelection.length
          this.orgData.push(obj)
        })
      },
      /**
       * 组织机构分配上一步
       */
      orgPreStep() {
        this.$emit('close')
        this.$emit('orgPreStep')
      },
      /**
       * 组织机构分配确认
       */
      orgConfirm() {
        let caseIdList = this.multipleSelection.map(v => {
          return v.cupoId
        })
        let caseNumList = []
        caseNumList.push(this.multipleSelection.length)
        let depIdList = []
        depIdList.push(this.$store.state.caseManage.case_allot_org.deptId)
        net.send({
          server: this.server.distributeCeaseInfoAgin,
          data: {
            caseIdList: caseIdList,
            caseNumList: caseNumList,
            depIdList: depIdList,
            disType: 0
          },
          loading: this.loading
        }).then((data) => {
          this.$emit('close')
          this.$emit('refresh')
          this.$message({
            type: 'info',
            message: '分配成功'
          })
        }, err => {
          this.$message({
            type: 'info',
            message: err.reason
          })
        })
      },
      /**
       * 组织机构分配取消
       */
      orgCancel() {
        console.log(1)
        this.$emit('close')
      }
    }
  }

</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .btns {
    padding: 20px;
  }

</style>
